<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="searchKeyWords" />

    <MyCase :list="renderList" @showDialog="showDialog" />

    <MyDialog
      :renderData="dialogData"
      v-show="isShowDialog"
      @closeDialog="isShowDialog = false"
    />
  </div>
</template>

<script>
import MyCase from '@/components/MyCase.vue'
import MyDialog from '@/components/MyDialog.vue'

export default {
  components: {
    MyCase,
    MyDialog,
  },

  data() {
    return {
      searchKeyWords: '',
      isShowDialog: false,
      list: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药',
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药',
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴',
        },
      ],

      dialogData: {
        date: '2022-01-01',
        doctor: '张三',
        diagnosis: '感冒',
        prescription: '感冒药',
      },
    }
  },

  methods: {
    showDialog(date) {
      this.isShowDialog = true

      this.dialogData = this.list.find((item) => item.date === date)
    },
  },

  computed: {
    renderList() {
      return this.list.filter((item) => {
        return (
          item.date.includes(this.searchKeyWords) ||
          item.doctor.includes(this.searchKeyWords) ||
          item.diagnosis.includes(this.searchKeyWords) ||
          item.prescription.includes(this.searchKeyWords)
        )
      })
    },
  },
}
</script>

<style scoped></style>
